package com.qiwo.common.utils;

import com.alibaba.fastjson.JSONObject;

public class HttpResult {

    // 响应码
    private Integer code;

    // 响应体
    private String body;

    public HttpResult() {
        super();
    }

    public HttpResult(Integer code, String body) {
        super();
        this.code = code;
        this.body = body;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }
    /**
     * 获取返回的jsonbody
     * @return jsonbody
     */
    public JSONObject getJsonBody(){
        JSONObject result = null;
        if(this.isSuccess()){
            result = JSONObject.parseObject(this.getBody());
        }
        return result;
    }
    /**
     * 判断返回结果是否成功
     * @return
     */
    public boolean isSuccess(){
        if(this.getCode() == 200){
            return true;
        }else {
            return false;
        }
    }
    @Override
    public String toString() {
        return "HttpResult{" +
                "code=" + code +
                ", body='" + body + '\'' +
                '}';
    }
}
